<template>
	<view class="share-content">
		
		<!-- 分享文章列表 -->
		<view class="share-article">
			<!-- 标题 -->
			<view class="title-tab">
				<view class="hot" @click="setActive(1)">
					<view class="title" :class="{'active':titleTabNum == '1'}">收藏的商品</view>
					<view class="underline" :class="{'active':titleTabNum == '1'}"></view>
				</view>
				<view class="new" @click="setActive(2)">
					<view class="title" :class="{'active':titleTabNum == '2'}">收藏的店铺</view>
					<view class="underline" :class="{'active':titleTabNum == '2'}"></view>
				</view>
			</view>
			<!-- 文章列表 -->
			<view class="article-list" v-if="titleTabNum == 1">		
				<view class="note-box" v-if="no_good">
					暂无记录
				</view>
				<view class="article" v-for="(item,key) in good_list" :key="key" @click="goGoodDetail(item.store_sku_id)">
					<view class="article-img">
						<image lazy-load="true"  :src="item.sku.image[0]" mode="w" class="article-img"></image>
					</view>
					<view class="info">
						<view class="good"><view>{{item.sku.name}}</view></view>
						<view class="discuss"><view>{{item.store_sku.real_price}}</view></view>					
					</view>	
				</view>	
			</view>
			<view class="article-list" v-if="titleTabNum == 2">
				<view class="note-box" v-if="no_store">
					暂无记录
				</view>
				<view class="article" v-for="(item,key) in store_list" :key="key" @click="goStoreDetail(item.store_id)">
					<view class="article-img">
						<image lazy-load="true"  :src="item.logo" mode="w" class="article-img"></image>
					</view>
					<view class="info">
						<view class="good"><view>{{item.name}}</view></view>
						<view class="discuss"><view>{{item.province}}{{item.city}}</view></view>					
					</view>	
				</view>	
			</view>
		</view>
	</view>
</template>

<script>
	// 瀑布流组件
	
	export default {
		data() {
			return {
				titleTabNum:'1',
				"checked":true,
				"checkAllSta":false,
				good_list:[],
				store_list:[],
				no_good:false,
				no_store:false,
				latitude:0,
				longitude:0
				
			}
		},
		onLoad() {
			
			var self = this;
			uni.getLocation({
			    type: 'wgs84',
			    success: function (res) {
					console.log(res)
					self.latitude = res.latitude;
					self.longitude = res.longitude;
					self.getGoodList();
					
			    },
				fail() {
					self.latitude = 30.657420;
					self.longitude = 104.065840;
					self.getGoodList();
				}
			});
			// #ifdef H5
			let share_time_line={
				title:self.$request.h5_share_name, // 分享标题
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			let share_app_message={
				title: self.$request.h5_share_name, // 分享标题
				desc: '我发现了一个很不错的商城，买家具有超大实惠！', // 分享描述
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			uni.setStorageSync('share_time_line',share_time_line);
			uni.setStorageSync('share_app_message',share_app_message);
			self.$request.wx_config()
			// #endif
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {
		      console.log(res.target)
		    }
		    return {
		      title: this.$request.share_title,
		      path: '/pages/index/index'
		    }
		  },
		methods: {
			setActive(num){
				this.titleTabNum = num;
				if(num==1){
					this.getGoodList()
				}else{
					this.getStoreList()
				}
			},
			checkImg(){
				this.checked = !this.checked
			},
			checkAll(){
				this.checkAllSta = !this.checkAllSta
			},
			getGoodList(){
				var self = this;
				self.$request.request({
					url:'/user/goods/list',
					data:{
						per:10000
					},
					success:function(res){
						if(res.code==200){
							var x = res.result;
							x.forEach((item,index)=>{
								x[index].sku.image = JSON.parse(item.sku.image);
								// console.log(JSON.parse(item.sku.image));
								x[index].store_sku.real_price = self.$money(item.store_sku.real_price);
								x[index].sku.image.forEach((val,key)=>{
									x[index].sku.image[key] = self.$http_img(val);
								})
							})
							self.good_list = x;
							if(self.good_list.length<1){
								self.no_good = true
							}else{
								self.no_good = false
							}
						}else{
							
						}
					}
				})
			},
			getStoreList(){
				var self = this;
				self.$request.request({
					url:'/user/store/list',
					data:{
						per:10000,
						lat:self.latitude,
						lng:self.longitude,
					},
					success:function(res){
						console.log(res)
						if(res.code==200){
							var x = res.result;
							x.forEach((item,index)=>{
								x[index].logo = self.$http_img(item.logo);
					
							});
							self.store_list = x;
							if(self.store_list.length<1){
								self.no_store = true
							}else{
								self.no_store = false
							}
							
						}else{
							
						}
					}
				})
			},
			goGoodDetail(id){
				uni.redirectTo({
					url:'../local-store-item/local-store-item?id='+id
				})
			},
			goStoreDetail(id){
				uni.redirectTo({
					url:'../local-store-home/local-store-home?id='+id+'&lat='+this.latitude+'&lng='+this.longitude
				})
			}
			
			
		}
	}
</script>

<style>
	@import url("my-goods.css");
</style>
